#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define XH(i,a,b) for(int i = a; i < b; ++i)
#define XXH(i,b,a) for(int i = b; i >= a; --i)
int tmpInt;LL tmpLL;string tmpStr;char tmpChar;
vector<int>tmpIntVector;
struct node{
    
};

void solve(){
     int n; cin>>n;
     int a[n];
     int c[3] = {0};
     XH( i , 0 , n ){
        scanf("%d", &a[i]); 
        if(a[i]%3==0)c[0]++;
        else if(a[i]%3==1)c[1]++;
        else c[2]++;
     }
     int index = c[0] > c[1] ? 0 : 1;
     index = c[index] > c[2] ? index : 2;
     int ans = c[index] - n/3;
     int index2 = (index + 1)%3;
     c[(index + 1)%3] += ans;
     int index3 = (index2 + 1)%3;
     if(c[(index + 1)%3] >n/3){
        ans += c[index2] - n/3;
     }else if(c[index2] < n/3){
        ans += 2*(c[(index3)] - n/3); 
     }
    cout<<ans<<endl;
}

int main(){
    int t; cin>>t;
    XH(i,0,t){
        solve();
    }

    return 0;
}

